#include <iostream>
using namespace std;
int a[1000005], b[1000005];
int main()
{
    int n, m;
    cin >> n >> m;
    char x;
    for (int i = 1; i <= n; i++) {
        cin >> x;
        if (x == '(')a[i] = 1;
        else a[i] = -1;
    }
    int op;
    for (int h = 1; h <= m; h++) {
        cin >> op;
        if (op == 1) {
            int l, r;
            cin >> l >> r;
            for (int i = l; i <= r; i++)a[i] *= -1;
        }
        else {
            int l, r = 0;
            cin >> l;
            int sum = a[l];
            for (int i = l + 1; i <= n; i++) {
                if (sum < 0) {
                    break;
                }
                sum += a[i];
                if (sum == 0)r = i;
            }
            cout << r << endl;
        }
    }
    return 0;
}